<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let person={
      name:'a',
      age:20,
      address:{
        city:'china'
      },
      arr:['b','c','d']
    }
    function deepClone(obj){
      if(typeof obj!=='object' || obj==null){
        return obj
      }
      let result
      if(obj instanceof Array){
        result=[]
      }else{
        result={}
      }
      for(let key in obj){
        //保证key不是原型的属性
        console.log(key);
        if(obj.hasOwnProperty(key)){
          result[key]=deepClone(obj[key])
        }
      }
      return result;
      
    }
    console.log(deepClone(person));
    

  </script>
</body>
</html>